#include "pch.h"
#include "MenuItem.h"

namespace GameStates
{

    MenuItem::MenuItem(const std::string& name, hgeSprite* sprite, float x, float y)
    {
        this->name = name;
        this->sprite = sprite;
        this->x = x;
        this->y = y;

        width = sprite->GetWidth();
        height = 100;                 //sprite->GetHeight();
        rect.x1 = x - width/2;
        rect.y1 = y - height/4;
        rect.x2 = rect.x1 + width;
        rect.y2 = rect.y1 + height/2;
    }

    void MenuItem::TellMousePos(float x, float y)
    {
        if(rect.TestPoint(x, y))
            isColliding = true;
        else
            isColliding = false;
    }

    void MenuItem::Render()
    {
        if(isColliding)
            sprite->SetTextureRect(0, height/2, width, height/2);
        else
            sprite->SetTextureRect(0, 0, width, height/2);
        sprite->Render(this->x, this->y);
    }
    
}